#!/usr/bin/python3
# -*-coding:utf-8 -*-

from pathlib import Path
import subprocess
import sys
import utils

def bench(binary: Path, input: Path, output: Path, log: Path):
    with open(log, "w", encoding="utf-8") as log, \
        open(output, "w", encoding="utf-8") as output:
        cmd = "time -v {} {}".format(binary, input)
        subprocess.call(cmd, stdout=output, stderr=log, shell=True)
        pass

if __name__ == '__main__':
    if len(sys.argv) == 4:
        v = sys.argv[1]
        t = sys.argv[2]
        i = sys.argv[3]

        binary = utils.pwd.joinpath("bin").joinpath(utils.binary(v, t))
        input = utils.pwd.joinpath("input").joinpath(utils.input(i))
        output = utils.pwd.joinpath("output").joinpath(utils.output(v, t, i))
        log = utils.pwd.joinpath("log").joinpath(utils.log(v, t, i))

        print(output)
        print(log)

        bench(binary, input, output, log)
    else:
        print(__file__, "<v>", "<t>", "<i>")
    pass
